
/**
 * 
 * 服务器访问地址
 */
//var forumHost = "http://www.yeeyi.com/bbs/forum.php?jsoncallback=?&mod=mobile";
var forumHost = "http://127.0.0.1/video_demo/mobileapi/videolist.php?jsoncallback=?&dopost=videolist";
var webAddr = "http://127.0.0.1";

var ipAddres = window.localStorage["ipAddres"] || '';
if(ipAddres != '') {
	var apiHost = "http://"+ipAddres+"/video_demo/mobileapi/videolist.php?jsoncallback=?&dopost=videolist";
	var webAddr = "http://"+ipAddres;
}



/**
 * 初始化用户信息
 */
function init(){
	var uid = getLocalStorge('uid');
	if(uid){
		var username = getLocalStorge('username');
		if(!username){
			username = '欢迎您';
		}
		//向菜单显示中组装数据
		$('#username').text(username);
		getNotice();
	}	
}

/**
 * 网络请求函数
 * @param {Object} url
 * @param {Object} callback
 */
function xmlHttp(url,callback){
	if(url == ''){
		uexWindow.alert('参数错误','请求地址不能为空！','返回');
	}else{
		var platform = getLocalStorge('platform');
		url = url + "&pf="+platform;
		$.getJSON(url,callback);
	}
}


/**
 * 显示个人菜单
 */
function showMenu(){
	if($('#menu').hasClass('hide')){
		//页面滚动到顶部以后再显示菜单
		window.scroll(0,0);
        $('#menu').removeClass('hide');
    }else{
        $('#menu').addClass('hide');
    }
}

/**
 * 初始化获取用户短信和提醒
 */
function getNotice(){
	var uid = getLocalStorge('uid');
	if(uid){
		var url = forumHost + '&ac=noprompt&uid='+uid;
		xmlHttp(url,showNotice);
	}
}

/**
 * 显示用户短信和提醒的数量
 * @param {Object} data
 */
function showNotice(data){
	var pm = data.newpm;
	var newprompt = data.newprompt;
	pm = '('+pm+')';
	newprompt = '('+newprompt+')';
	$('#prompt').html(newprompt);
	$('#pm').html(pm);
}

/**
 * 菜单选项跳转函数
 * @param {Object} type
 */
function goTarget(type){
	$('#menu').addClass('hide');
	if(type == 'notice'){
		$('#prompt').html('(0)');
		changeStatus('newprompt');
		uexWindow.open('notice','0','notice.html','2','100%','100%',4);
	}else if(type == 'message'){
		$('#pm').html('(0)');
		changeStatus('newpm');
		uexWindow.open('message','0','message_list.html','2','100%','100%',4);
	}else if(type == 'mythread'){
		uexWindow.open('mythread','0','mythread.html','2','100%','100%',4);
	}else if(type == 'newthread'){
		uexWindow.open('newthread','0','newthread.html','2','100%','100%',4);
	}else if(type == 'backlist'){
		uexWindow.evaluateScript("threadWindow","0","closeWindow()");
	}else if(type == 'backmain'){
		uexWindow.evaluateScript("forum_list","0","closeWindow()");
	}else if(type == 'favorite'){
		uexWindow.open('favorite','0','favorite.html','2','100%','100%',4)
	}else if(type == 'logout'){
		uexWidgetOne.exit();
	}
}

/**
 * 封装的获取本地localStorage值
 * @param {Object} key
 */
function getLocalStorge(key){
	var item = localStorage.getItem(key);
	if(item=='' || item==null || typeof(item)=="undefined"){
		return false;
	}else{
		return item;
	}
}

/**
 * 改变在线提醒或短信息状态
 * @param {Object} type
 */
function changeStatus(type){
	var uid = getLocalStorge('uid');
	var pwd = getLocalStorge('pwd');
	var url = forumHost + '&ac=message&type=change&uid='+uid+'&pwd='+pwd+'&do='+type; 
	xmlHttp(url,showChange);
}

function showChange(data){
	//Do nothing
}

/**
 * 页面滚动到顶部
 */
function pageScroll() {
	window.scrollBy(0,-50);
	scrolldelay = setTimeout('pageScroll()',1);
	var scrollTop = document.documentElement.scrollTop || window.pageYOffset;
	if(scrollTop==0){
		clearTimeout(scrolldelay);
	}
}
